package br.com.rsrpp.application.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import br.com.rsrpp.domain.model.PS;
import br.com.rsrpp.domain.model.Usuario;
import br.com.rsrpp.domain.service.PSService;
import br.com.rsrpp.domain.service.UserService;

@Controller
public class HomeController {

	@Autowired
	private PSService PSService;
	
	@Autowired
	private UserService userService;
	
    @RequestMapping(value = "/carregarHome")
    public String carregarHome(Model model) {
    	
    	List<PS> listaPS = PSService.buscarTodosPS();
    	List<Usuario> listaUser = userService.buscarTodos();
    	    	
    	model.addAttribute("listaPS", listaPS);
    	model.addAttribute("listaUser", listaUser);
    	
        return "home";
    }
 
    @RequestMapping(value = "/carregarLogin")
    public String Login() {
   	    return "Login";
    }
    
    @RequestMapping(value = "/logout")
    public String Login(HttpSession session) {
   	    
    	session.invalidate();
    	return "redirect:/carregarLogin.html?logout";
    }
    
    @RequestMapping(value = "/inserts")
    public String inserts() {
   	    
    	PSService.inserts();
    	
    	return "redirect:/carregarLogin.html";
    }
}
